<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets SoapServer persistence mode</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="soapserver.setobject.html">« SoapServer::setObject</a></li>
      <li style="float: right;"><a href="class.soapfault.html">SoapFault »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.soapserver.html">SoapServer</a></li>
    <li>Sets SoapServer persistence mode</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="soapserver.setpersistence" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SoapServer::setPersistence</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SoapServer::setPersistence</span> &mdash; <span class="dc-title">Sets SoapServer persistence mode</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-soapserver.setpersistence-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SoapServer::setPersistence</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment"> 
   This function allows changing the persistence state of a SoapServer object between
   requests. This function allows saving data between requests utilizing PHP sessions.  This method
   only has an affect on a SoapServer after it has exported functions utilizing <span class="methodname"><a href="soapserver.setclass.html" class="methodname">SoapServer::setClass()</a></span>. 
  </p>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para"> 
     The persistence of <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> makes only
     objects of the given class persistent, but not the class static data. In this 
     case, use <var class="varname">$this->bar</var> instead of self::$bar. 
    </p>
   </p></blockquote>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
     <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> serializes data on the class object between requests. In order to properly utilize resources (e.g. <span class="classname"><a href="class.pdo.html" class="classname">PDO</a></span>), <a href="language.oop5.magic.html#object.wakeup" class="link">__wakeup()</a> and <a href="language.oop5.magic.html#object.sleep" class="link">__sleep()</a> magic methods should be utilized. 
    </p>  
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-soapserver.setpersistence-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">mode</code></dt>

     <dd>

      <p class="para">
       One of the <code class="literal">SOAP_PERSISTENCE_XXX</code> constants.
      </p>
      <p class="para">
       <strong><code>SOAP_PERSISTENCE_REQUEST</code></strong> - SoapServer data does not persist between
       requests. This is the <em class="emphasis">default</em> behavior of any SoapServer
       object after setClass is called. 
      </p>
      <p class="para">
       <strong><code>SOAP_PERSISTENCE_SESSION</code></strong> - SoapServer data persists between requests.
       This is accomplished by serializing the SoapServer class data into
       <var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION['_bogus_session_name']</a></var>, because of this 
       <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> must be called before this persistence mode is set. 
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-soapserver.setpersistence-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-soapserver.setpersistence-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5345">
    <p><strong>示例 #1 <span class="function"><strong>SoapServer::setPersistence()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">MyFirstPersistentSoapServer&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;</span><span style="color: #0000BB">$resource</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;(Such&nbsp;as&nbsp;PDO,&nbsp;mysqli,&nbsp;etc..)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;</span><span style="color: #0000BB">$myvar1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;</span><span style="color: #0000BB">$myvar2</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__wakeup</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">//&nbsp;We're&nbsp;calling&nbsp;our&nbsp;wakeup&nbsp;to&nbsp;handle&nbsp;starting&nbsp;our&nbsp;resource<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__wakeup</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">resource&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">CodeToStartOurResourceUp</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__sleep</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;We&nbsp;make&nbsp;sure&nbsp;to&nbsp;leave&nbsp;out&nbsp;$resource&nbsp;here,&nbsp;so&nbsp;our&nbsp;session&nbsp;data&nbsp;remains&nbsp;persistent<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Failure&nbsp;to&nbsp;do&nbsp;so&nbsp;will&nbsp;result&nbsp;in&nbsp;the&nbsp;failure&nbsp;during&nbsp;the&nbsp;unserialization&nbsp;of&nbsp;data<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;on&nbsp;the&nbsp;next&nbsp;request;&nbsp;thus,&nbsp;our&nbsp;SoapObject&nbsp;would&nbsp;not&nbsp;be&nbsp;persistent&nbsp;across&nbsp;requests.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;array(</span><span style="color: #DD0000">'myvar1'</span><span style="color: #007700">,</span><span style="color: #DD0000">'myvar2'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;}<br /><br />&nbsp;try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapServer</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'uri'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'REQUEST_URI'</span><span style="color: #007700">]));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'MyFirstPersistentSoapServer'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;setPersistence&nbsp;MUST&nbsp;be&nbsp;called&nbsp;after&nbsp;setClass,&nbsp;because&nbsp;setClass's<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;behavior&nbsp;sets&nbsp;SESSION_PERSISTENCE_REQUEST&nbsp;upon&nbsp;enacting&nbsp;the&nbsp;method.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setPersistence</span><span style="color: #007700">(</span><span style="color: #0000BB">SOAP_PERSISTENCE_SESSION</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">();<br />&nbsp;}&nbsp;catch(</span><span style="color: #0000BB">SoapFault&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_log</span><span style="color: #007700">(</span><span style="color: #DD0000">"SOAP&nbsp;ERROR:&nbsp;"</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br />&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-soapserver.setpersistence-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="soapserver.setclass.html" class="methodname" rel="rdfs-seeAlso">SoapServer::setClass()</a> - Sets the class which handles SOAP requests</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>